package com.guit.hrms.service.impl;

import com.guit.hrms.dto.MatterDTO;
import com.guit.hrms.mapper.MatterMapper;
import com.guit.hrms.po.Matter;
import com.guit.hrms.service.MatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MatterServiceImpl implements MatterService {
    @Autowired
    private MatterMapper matterMapper;

    /**
     * 查询员工个人待办事项
     * @param employeeId 员工id
     * @return 待办事项列表
     */
    @Override
    public List<Matter> queryMatter(String employeeId) {
        return matterMapper.queryMatter(employeeId);
    }

    /**
     * 添加待办事项
     * @param matterDTO 待办事项信息
     * @return 添加结果
     */
    @Override
    public Integer addMatter(MatterDTO matterDTO) {
        if (matterDTO.getEmployeeId() != null && matterDTO.getMatterContent() != null
                && matterDTO.getStartTime() != null && matterDTO.getEndTime() != null
                && matterDTO.getStartTime().isBefore(matterDTO.getEndTime())) {
            return matterMapper.addMatter(matterDTO);
        } else {
            return 0;
        }
    }

    /**
     * 修改待办事项
     * @param matterDTO 待办事项信息
     * @return 修改结果
     */
    @Override
    public Integer updateMatter(MatterDTO matterDTO) {
        if (matterDTO.getId() != null && (matterDTO.getMatterContent() != null
                || (matterDTO.getStartTime() != null && matterDTO.getEndTime() != null
                && matterDTO.getStartTime().isBefore(matterDTO.getEndTime())))){
            return matterMapper.updateMatter(matterDTO);
        } else {
            return 0;
        }
    }

    /**
     * 完成待办事项
     * @param id 待办事项id
     * @return 处理结果
     */
    @Override
    public Integer finishMatter(Integer id) {
        return matterMapper.finishMatter(id);
    }
}
